package com.springcloud.netflix.eureka.eurekaribbonclient.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author 纪翔宇
 */
@Service
public class ComputeService {

    @Autowired
    RestTemplate restTemplate;

   @HystrixCommand(fallbackMethod = "testHystrixFallback")
    public String testHystrix() {
        return restTemplate.getForEntity("http://SERVICE-FEIGN/ribbonhello?name=jeremy", String.class).getBody();
    }

    /**
     * 发生错误时的回调
     * @return 错误信息
     */
    public String testHystrixFallback() {
        return "error info from ribbon!";
    }


}
